package com.sky.edumanageapi.order.controller;

import com.sky.edumanageapi.base.response.JsonResult;
import com.sky.edumanageapi.order.mapper.OrderMapper;
import com.sky.edumanageapi.order.pojo.dto.OrderQuery;
import com.sky.edumanageapi.order.pojo.dto.OrderSaveParam;
import com.sky.edumanageapi.order.pojo.entity.Order;
import com.sky.edumanageapi.order.pojo.vo.OrderVO;
import com.sky.edumanageapi.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/order")
@Api(tags = "订单管理")
public class OrderController {
    @Autowired
    OrderService orderService;


    @ApiOperation(value = "获取订单列表")

    @GetMapping("/list")//**获取订单列表*
    public JsonResult selectAll(OrderQuery orderQuery){
log.debug("查询订单所有的数据:{}",orderQuery );
        List<Order> orderVOS = orderService.selectAll(orderQuery);
        return JsonResult.ok(orderVOS);
    }
    @ApiOperation(value = "创建订单")
    @PostMapping("/create")//**创建订单**
    public JsonResult save(OrderSaveParam orderSaveParam){
        log.debug("新增一条订单的数据:{}", orderSaveParam);
        orderService.save(orderSaveParam);
        return JsonResult.ok();
    }
    @ApiOperation(value = "支付订单")
    @PostMapping("/detail/{orderId}")//**支付订单**
    public JsonResult update(@PathVariable Integer orderId){
        log.debug("修改一条订单的数据成为支付:{}", orderId);
        orderService.update(orderId);
        return JsonResult.ok();
    }
    @ApiOperation(value = "删除订单")
    @PostMapping("/delete/{orderId}")//**支付订单**
    public JsonResult delete(@PathVariable Integer orderId){
        log.debug("删除一条订单的数据状态修改为取消:{}", orderId);
        orderService.delete(orderId);
        return JsonResult.ok();
    }
    @ApiOperation(value = "获取订单详情")
    @PostMapping("/pay/{orderId}")//**获取订单详情**:
    public JsonResult selectByorderId(@PathVariable Integer orderId){
        log.debug("获取一条已经支付订单信息的数据:{}", orderId);
        Order order = orderService.selectByOrderId(orderId);
        return JsonResult.ok(order);
    }



}
